<?php
//Configure::write('debug', 2);
$this->pageTitle = "Products from " . $producer['Member']['business_name'];
?>
<h2><a name="top"><?=$producer['Member']['business_name']?></a></h2>
<div id="breadcrumbs">
<?=$html->link('Producers','/producers')?>
 &gt;
<?=$html->link($producer['Member']['business_name'],'/producers/products/' . $producer['Producer']['producer_id']);?>
</div>
<p><?=$html->link("About us", array('controller' => 'producers', 'action' => 'about', $producer['Member']['username']))?></p>
<?php

$open = $this->requestAction('/deliveries/isOpen');
if (!$open) {
	echo '<p class="note">Note: prices may be subject to change before the ordering period opens.</p>';
}

if (empty($products)) {
?>
<p>This producer has no items for sale this order cycle.  However, they are still participating with the Co-op: keep an eye out for them at the pickup, or contact them directly by going to <?=$html->link("About us",'/producers/about/' . $producer['Producer']['producer_id'])?>.</p>
<?php
} else {
?>
<h3>Sorted By: <?=$sorting?></h3>
<p>Sort By:
<?php
	$s = array();
	foreach($sorts as $name => $sort) {
		$s[] = $html->link($name,'/producers/products/' . $producer['Producer']['producer_id'] . '/' . $name);
	}
	echo implode(', ',$s);
?></p>
<?php
	$m = $this->requestAction('/members/getLoggedInId');
	$t = '';
	$c = '';
	foreach($products as $product) {
		if ($sorting == 'Category') {
			$comp = $product['Category']['category_name'] . ': ' . $product['Subcategory']['subcategory_name'];
			if ($comp != $c) {
				if ($comp == ': ') { $comp = 'Uncategorized'; }
				$c = $comp;
				$t .= '<h4><a name="' . $product['Subcategory']['subcategory_id'] . '">' . $comp . '</a> <a href="#top" class="action">[Back to Top]</a></h4>' . "\n";
				$cats[$product['Subcategory']['subcategory_id']] = $comp;
			}
		}
		$t .= $this->renderElement('product',array('product'=>$product,'open'=>$open,'m'=>$m));
	}
	if ($sorting == 'Category') {
		echo '<p>Jump to: ';
		$c = array();
		foreach($cats as $id => $cat) {
			$c[] = "<a href='#$id'>$cat</a>";
		}
		echo implode(', ',$c);
		echo '</p>' . "\n";
	}
	echo $t;
}
//Configure::write('debug', 2);
//pr($products);
?>
<div style="clear:both"></div>
